package eerbaar.v2.app.tasks;

import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;

import eerbaar.game.IGame;
import eerbaar.persona.IPersona;
import eerbaar.shared.service.ServiceFactory;
import eerbaar.v2.app.GameHelper;
import eerbaar.v2.app.mover.IPersonaMover;
import eerbaar.v2.app.mover.PersonaMover;

public class PetMoveTask implements IGameTask {

    private final List<PersonaMover> movers = new ArrayList<PersonaMover>();

    private void createMovers() {

        Global.IPersonaFiler filter = new Global.IPersonaFiler() {

            @Override
            public boolean canInclude(IPersona p) {

                if (p.getName().equals("dog")) {
                    return true;
                }

                return false;
            }
        };

        Global.createMovers(this.movers, filter);
    }

    @Override
    public void doTask(Graphics2D g) {

        IGame game = GameHelper.getGame();
        if (game == null) {
            return;
        }

        createMovers();
        for (IPersonaMover mover : this.movers) {
            mover.triggerMove();
        }

        IPersonaMover mover = ServiceFactory.getService(IPersonaMover.class);
        if (mover != null) {
            mover.triggerMove();
        }
    }

    @Override
    public Priority getPriority() {
        return Priority.FIRST;
    }

    @Override
    public int getRate() {
        return IGameTask.STANDARD_RATE;
    }

    @Override
    public boolean runWhenSuspended() {
        return false;
    }

}
